﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using Microsoft.Practices.Composite.Regions;
using DevFX.Modules.Passport.UserModule.View;
using Microsoft.Practices.Unity;
using DevFX.Modules.Passport.UserModule.ViewModule;

namespace DevFX.Modules.Passport
{
    public partial class DefaultView : UserControl
    {
        private readonly IUnityContainer container = null;
        private readonly IRegionManager regionManager = null;

        public DefaultView()
        {
            InitializeComponent();
        }

        public DefaultView(IUnityContainer container, IRegionManager regionManager)
            : this()
        {
            this.container = container;
            this.regionManager = regionManager;
        }

        public void Display()
        {
            RegisterServices();
            IUserView view = container.Resolve<IUserView>();
            IUserViewModel viewModel = container.Resolve<IUserViewModel>();
            view.ApplyModel(viewModel);
            regionManager.AddToRegion(PassportRegionNames.PassportMainRegion, view);
        }

        private void RegisterServices()
        {
            container.RegisterType<IUserView, UserView>();
            container.RegisterType<IUserViewModel, UserViewModel>();
        }
    }
}
